home *** CD-ROM | disk | FTP | other *** search
- Path: beta.nedernet.nl!usenet
- From: jos@and.nl (Jos A. Horsmeier)
- Newsgroups: comp.lang.c
- Subject: Re: Memory deallocation and linked lists
- Date: 17 Apr 1996 10:26:59 GMT
- Organization: AND Operations Research B.V.
- Message-ID: <4l2h1j$lgd@beta.nedernet.nl>
- References: <4l1hpk$hk5@alice.walrus.com>
- NNTP-Posting-Host: klepzeiker.and.nl
- Mime-Version: 1.0
- Content-Type: Text/Plain; charset=ISO-8859-1
- X-Newsreader: WinVN 0.99.5
-
- In article <4l1hpk$hk5@alice.walrus.com>, warrenj@walrus.com wrote:
-
- |Greetings!
- |Let us suppose I have a singularly linked list. If i free up the first
- |node, will all of the rest of the nodes be freed up as well? Free
- |meaning, using the borland command free(). Do I have to free up each node
- |seperately? Something I've never actually known >:). Thanks in advance.
-
- Yes, you have to free every single element yourself. The reason is, that
- malloc(), after allocating the memory for you, doesn't know what this
- memory is going to be used for (and it couldn't care less actually ;-)
- So, if you're going to use this piece of memory as a list element,
- nobody else knows about it, i.e. nobody knows that there exists a pointer
- value stored in this piece of memory, pointing to another piece of memory ...
-
- kind regards,
-
- Jos aka jos@and.nl
- --
- Atnwgqkrl gy zit vgksr, ug qshiqwtzoeqs!
-
-